<!DOCTYPE html>
<html class="x-admin-sm">
<head>
  <meta charset="UTF-8">
  <title>欢迎页面-X-admin2.2</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
  <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
  <!--[if lt IE 9]>-->
  <!--<script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>-->
  <!--<script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>-->
  <link  rel="stylesheet" href="./company.css" >
  <link rel="stylesheet" href="http://api.map.baidu.com/library/DrawingManager/1.4/src/DrawingManager_min.css" />
  <link rel="stylesheet" href="http://api.map.baidu.com/library/SearchInfoWindow/1.4/src/SearchInfoWindow_min.css" />
  <script type="text/javascript" src="../../common/js/public.js"></script>
  <script type="text/javascript" src="../../common/js/publicUtils.js"></script>
  <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=G3GKeZsowwfaOlY71VAd0TfR"></script>
  <script type="text/javascript" src="http://api.map.baidu.com/library/DrawingManager/1.4/src/DrawingManager_min.js"></script>
  <link rel="stylesheet" href="http://api.map.baidu.com/library/DrawingManager/1.4/src/DrawingManager_min.css" />
  <script type="text/javascript" src="http://api.map.baidu.com/library/SearchInfoWindow/1.4/src/SearchInfoWindow_min.js"></script>
</head>
<style>
  .org-attr td input, .org-attr td select {
    text-align: left;
    width: 100%; !important;
    border: none;
    background: none;
    padding-left: 20px;
    color: black;
  }
</style>
<body>
<div class="layui-fluid" id="flowDiv" onload="onLoad()">
  <div class="zTreeBackground left" style="float: left;width:300px">
    <div class="titlediv">
      <p style="text-align:right;background-color:white;line-height: 30px">
        组织信息<i class="layui-icon layui-icon-refresh" style="margin-left: 36%" onclick="refreshRoot()"></i>&ensp;&ensp;
      </p>

    </div>
    <div class="searchdiv" >
      <div class="layui-input-inline" style="width:100%">
        <input type="text" style="height: 30px !important" id="search" name="keyword" autocomplete="off" class="layui-input" placeholder="请输入名称"/>
        <i class="layui-icon layui-icon-search" style="position: absolute;top:8px;right: 8px;" onclick="searchByName()"></i>
      </div>
    </div>
    <div class="ztreediv" id="ztreediv">
      <div class="ztreeuldiv">
        <ul id="treeStructure" class="ztree"></ul>
      </div>
    </div>
  </div>
  <div class="zTreeBackground right" style="float: left; padding-left:1%;width:70%">
      <div id="toolbar" style="height: 40px"></div>
      <div style="margin-top: 10px;">
        <table border="1" class="layui-table org-attr"  lay-size="sm" >
          <tbody>
          <tr>
            <th>名称</th>
            <td><input type="text" class="layui-input"  id="name" disabled/></td>
            <th>组织类型</th>
            <td id="td_type" class="layui-form">
              <select name="type" id="type"></select>
            </td>
          </tr>
          <tr>
            <th>简称</th>
            <td><input type="text" class="layui-input"  id="shortName" disabled/></td>
            <th>组织级别</th>
            <td class="layui-form">
              <select name="hierarchy" id="hierarchy"></select>
            </td>
          </tr>
          <tr>
            <th>状态</th>
            <td class="layui-form">
              <select name="state" id="state"></select>
            </td>
            <th>排&emsp;&emsp;序</th>
            <td><input type="text" class="layui-input"  id="sort" disabled/></td>
          </tr>
          <tr>
            <th>编码</th>
            <td><input type="text" class="layui-input"  oninput="this.value=this.value.replace(/[\u4e00-\u9fa5]/ig,'')" id="orgCode" disabled/></td>
            <th>域&emsp;&emsp;名</th>
            <td><input type="text" class="layui-input"  id="domainName" disabled/><!--<select hidden="true" class="" id="org_state_s"></select>--></td>
          </tr>
          <tr>
            <th>电话</th>
            <td><input type="text" class="layui-input"  oninput="this.value=this.value.replace(/[\u4e00-\u9fa5]/ig,'')" id="phone" disabled/></td>
            <th>传&emsp;&emsp;真</th>
            <td><input type="text" class="layui-input"  id="fax" disabled/><!--<select hidden="true" class="" id="org_state_s"></select>--></td>
          </tr>
          <tr>
            <th>邮编</th>
            <td><input type="text" class="layui-input"  oninput="this.value=this.value.replace(/[\u4e00-\u9fa5]/ig,'')" id="postalCode" disabled/></td>
            <th>网&emsp;&emsp;站</th>
            <td><input type="text" class="layui-input"  id="webSite" disabled/><!--<select hidden="true" class="" id="org_state_s"></select>--></td>
          </tr>
          <tr>
            <th>地址</th>
            <td><input type="text" class="layui-input" id="address" disabled/></td>
            <th>GPS坐标</th>
            <td>
              <div>
                <input type="text" class="layui-input" name="gps" id="gps" disabled/>
                <button id="project_gps_btn" style="top: 4px;right: 9px;bottom: 4px;display: none;" class="btn_gps" onclick="getGps()">选择</button>
              </div>
            </td>
          </tr>
          </tbody>
        </table>
      </div>
    <div>
      <h3 class="tab_header"><span></span>直属下级表</h3>
      <table id="companyTable" lay-filter="test"></table>
      <!-- <script type="text/html" id="barDemo">
           <img lay-event="edit" src="../../common/images/Buttonico/Butt_Edit.png" />
           <img lay-event="del" src="../../common/images/Buttonico/Butt_Delete.png" />
       </script>-->
    </div>
  </div>
  <div id='gpsmap' style="display: none;height: 100%;">
    <div id="allmap" style="overflow:hidden;zoom:1;position:relative;width: 100%; height:100%;">
      <div id="map" style="height:100%;-webkit-transition: all 0.5s ease-in-out;transition: all 0.5s ease-in-out;"></div>
    </div>
</div>
</body>
<script type="text/javascript">
    var zTreeObj,nodes,nodeSelected,urlForIframePro,urlForIframeCom,parentNode;
    var parentId,parentType,node, parentName, form,layer, obj_datas, index_i1,orgLevelMap;
    var chnNumChar = ["零","一","二","三","四","五","六","七","八","九"];
    var overlays = [],map;

    $(document).ready(function() {
        orgLevelMap=getDic("OrgLevel");
        loadbutton("toolbar");//加载按钮loadbutton(id)，id为button容器id，不传默认为buttongroup
        urlForIframePro = '../companymanage/projectmsg/project.html';
        urlForIframeCom = '../companymanage/projectmsg/company.html';
        initTree("#treeStructure");
        loadSelect();
        //$(".org-attr td :input").attr("disabled", "disabled");
        layui.use('layer',function(){layer = layui.layer;})
    })
    /* *
     * @Author bxf
     * @Description setting配置
     * @Date 14:33 2019/8/28
     * @param null
     * @return
     */
    var setting = {
        check: {
            //enable: true,
            //chkboxType: { "Y": "s", "N": "s" }
        },
        edit:{
            enable: false,
        },
        async: {
            enable: true,
            url: publicUrl+"company/getByPid",
            headers: {"Authorization":getData("Authorization")},
            dataFilter: formatedata,
            otherParam:{//传入查询参数
                //注意，要传入动态变化的参数必须用return的方式
                "name":function(){return $("#search").val()
                }
            },

            autoParam: ["id"]
        },
        data: {
            simpleData: {
                enable: true,
                idKey:"id",
                pIdKey:"pid",
                isParent:"parent",
                rootPid:""
            },
            key: {
                isParent:"parent",
                url: "xUrl",
                icon:"xIcon",
                level:"orgLevel",
                name:"shortName"
            }
        },
        callback: {
            beforeClick: beforeClick,
            onClick: zTreeOnClick,
            onAsyncSuccess: zTreeOnAsyncSuccess
        }
    };

    window.onload = getContentSize;
    window.onresize = getContentSize;

    function zTreeOnAsyncSuccess(){
        var node = zTreeObj.getNodeByParam('id', nodeSelected.id);//获取id为1的点
        zTreeObj.selectNode(node);//选择点
        zTreeObj.setting.callback.onClick(null, zTreeObj.setting.treeId, node);//调用事件
    }
    /**
     * 页面自适应
     */
    function getContentSize() {
        var wh = document.documentElement.clientHeight;
        var eh = 30;
        ch = (wh - eh) + "px";
        document.getElementById( "flowDiv" ).style.height = ch;
        document.getElementById( "ztreediv" ).style.height = (wh - eh - 50)+"px";
        document.body.style.height = (wh)+"px";
    }
    /* *
     * @Author bxf
     * @Description 刷新树
     * @Date 11:16 2019/8/28
     * @param null
     * @return
     */
    function refreshRoot(){
        initTree("#treeStructure");
    }
    //zTreeObj = $.fn.zTree.init($("#treeStructure"), setting, zNodes);
    function formatedata(treeId,parentNode,responseData) {
        return changeIcon(formatTreeParseData(treeId,parentNode,responseData,null));
    }

    function searchByName(){
        var search = $("#search").val();
        if(!search){
            return ;
        }
        loadTree("#treeStructure");
    }
    /* *
     * @Author bxf
     * @Description 加载树
     * @Date 14:31 2019/8/28
     * @param null
     * @return
     */
    function loadTree(id){
        $(id).html('');
        publicAjax (null,'company/getOrgForTree',{"shortName":$("#search").val()},false,null,function(data){
            zTreeObj = $.fn.zTree.init($(id),setting, changeIcon(data.data));
            zTreeObj.expandAll(true);
        })
    }

    function initTree(id){
        zTreeObj = null;
        $(id).html('');
        publicAjax(null,'company/getByPersonId',{},false,null,function(data){
            zTreeObj = $.fn.zTree.init($(id),setting, changeIcon(data.data));
        })
    }

    // zTree 的参数配置，深入使用请参考 API 文档（setting 配置详解）

    function beforeClick(treeId, treeNode, clickFlag) {
        
    }


    function zTreeOnClick(event, treeId, treeNode, clickFlag) {
        canceEdit();
        nodeSelected = treeNode;
        parentNode = zTreeObj.getNodeByParam("id",treeNode.parentId,null);
        initForm(nodeSelected);
        getProlist(nodeSelected);

    }

    function setFontCss_ztree(treeId, treeNode) {
        if (treeNode.id == 0) {
            //根节点
            return {color: "#333", "font-weight": "500"};
        } else if (treeNode.isParent == false) {
            //叶子节点
            return (!!treeNode.highlight) ? {color: "#ff0000", "font-weight": "bold"} : {
                color: "#660099",
                "font-weight": "normal"
            };
        } else {
            //父节点
            return (!!treeNode.highlight) ? {color: "#ff0000", "font-weight": "bold"} : {
                color: "#333",
                "font-weight": "normal"
            };
        }
    }

    function insertAfter(newEl, targetEl){
        var parentEl = targetEl.parentNode;

        if(parentEl.lastChild == targetEl)
        {
            parentEl.appendChild(newEl);
        }else
        {
            parentEl.insertBefore(newEl,targetEl.nextSibling);
        }
    }

    //初始化编辑按钮
    function initEdit(val){
        if(!nodeSelected){
            layerror("请选择组织！");
            return ;
        }
        //$("#type,#hierarchy,#state").css('display', 'none');
        //$("#org_state,#org_level,#org_type").css('display', 'inline-block');
        $(".org-attr td :input").removeAttr("disabled");
        $("#project_gps_btn").css('display','inline-block');
        //设置选中值
        $(val).attr("onclick","initSave(this)");
        $(val).html("<i class='layui-icon'>&#xe608;</i>保存");
        var obox=document.getElementById("toolbar");
        $(val).attr("option_flag","edit");
        $("#toolbar").append("<button type='button' id='canceEndit' style='float: left;margin-left: 12px' class='layui-btn layui-btn-normal' onclick='canceEdit()'><i class='layui-icon'></i>取消</button>");
        form.render();
    }
    /* *
    * @Author bxf
    * @Description 重置按钮
    * @Date 15:37 2019/10/31
    * @param null
    * @return
    */
    function canceEdit(){
        $("#save,#back,#project_gps_btn").css('display','none');
        form.render();
        var nodes = zTreeObj.getSelectedNodes()[0];
        initForm(nodes);
        $("button[option_flag='edit']").attr("onclick","initEdit(this)");
        $("button[option_flag='edit']").html("<i class='layui-icon'>&#xe608;</i>编辑");
        $("#canceEndit").remove();
    }


    function loadSelect(){
        layui.use("form",function(){
            form = layui.form;
            //初始化组织级别
            publicAjax(null,'infdictitem/selectInfdictitemByInfdictsortCode',{'code':'OrgLevel'},false,null,function (data){
                if(data.code == 2000){
                    var selectStr = '';
                    var json= data.data;
                    for(var i=0;i<json.length;i++){
                        selectStr = selectStr + "<option value='"+json[i].code+"'>"+json[i].name+"</option>";
                    }
                    $("#hierarchy").html('');
                    $("#hierarchy").html(selectStr);

                }
            });
            //初始化组织类型
            publicAjax(null,'infdictitem/selectInfdictitemByInfdictsortCode',{'code':'OrgType'},false,null,function (data){
                if(data.code == 2000){
                    var selectStr = '';
                    var json= data.data;
                    for(var i=0;i<json.length;i++){
                        selectStr = selectStr + "<option value='"+json[i].code+"'>"+json[i].name+"</option>";
                    }
                    $("#type").html('');
                    $("#type").html(selectStr);
                }
            });
            //初始化用户状态
            publicAjax(null,'infdictitem/selectInfdictitemByInfdictsortCode',{'code':'UserState'},false,null,function (data){
                if(data.code == 2000){
                    var selectStr = '';
                    var json= data.data;
                    for(var i=0;i<json.length;i++){
                        selectStr = selectStr + "<option value='"+json[i].code+"'>"+json[i].name+"</option>";
                    }
                    $("#state").html('');
                    $("#state").html(selectStr);
                }
            });
            form.render();
        })
    }

    //初始化添加按钮
    function initAdd(){
        if(!nodeSelected){
          layerror("请选择组织！");
          return ;
        }
        var iframeWin ;
        var index = layer.open({
            type: 2,
            area: ["910px" , "560px"],
            fix: false,
            title: '新增组织',
            //不固定 
            shade: 0.3,
            content: './addorganization.html',
            btn: ['应用','完成','取消'],
            maxmin: false,
            success: function(layero, index) {
                iframeWin = layero.find('iframe')[0];
            },
            yes: function(index, layero) {
                var result = iframeWin.contentWindow.submitcreate('company/insertOrUpdate');
                if(result.code==2000){
                    zTreeObj.reAsyncChildNodes(nodeSelected, "refresh");
                    index_i1 = '';
                }

            },
            btn2: function(index, layero) {
                index_i1 = index;
                var result = iframeWin.contentWindow.submitcreate('company/insertOrUpdate');
                if(result.code==2000){
                    zTreeObj.reAsyncChildNodes(nodeSelected, "refresh");
                }
                return false;
            },
            btn3: function(index, layero) {
            },
            cancel: function(index, layero) {
            }
        });
    }

    function initMoveTo(){
        if(!nodeSelected){
            layerror("请选择组织！");
            return ;
        }
        var index = layer.open({
            type: 2,
            title: '移动组织',
            //			maxmin: true,
            shadeClose: false, //点击遮罩关闭层
            area: ['430px', '600px'],
            //			content: '../alert/addProject.html',
            content: 'selecttree.html',
            btn: ['确定','取消'],
            maxmin: false,
            success: function(layero, index) {
                $("#formTest1 select[name='state']").val(1);
                //form.render("select");
            },
            yes: function(index, layero) {
                var node = layero.find("iframe")[0].contentWindow.nodeSelected;
                if(typeof(node)!="undefined" && node !=""){
                    if(node.id == nodeSelected.id){
                        layer.alert("非法移动");
                        return;
                    }
                    if(nodeSelected.hierarchy-node.hierarchy!=1){
                        layer.alert("非法移动");
                        return;
                    }
                    var url = 'company/insertOrUpdate';
                    var from ={
                        id:obj_datas.id,
                        parentId:node.id,
                        name:$("#name").val(),
                        shortName:$("#shortName").val(),
                        orgCode:$("#orgCode").val(),
                    };
                    publicAjax(null,url,from,null,null,function (data){
                        if(data.code==2000){
                            initTree("#treeStructure");
                            initForm(from);
                            //$("#state,#hierarchy,#type").css('display','inline-block');
                            $("#state").val($("#state").val());
                            $("#hierarchy").val($("#hierarchy").val());
                            $("#type").val($("#type").val());
                            $("#save,#back,#project_gps_btn").css('display','none');
                            form.render();
                        }else{
                            layer.alert(data.msg);
                        }
                    })
                    layer.close(index);
                }else{
                    layer.alert("请选择组织");
                }

            },
            cancel: function(index, layero) {
            }
        });
    }

    /* *
     * @Author bxf
     * @Description 删除记录
     * @Date 11:19 2019/7/23
     * @param null
     * @return
     */
    function  initDelete() {
        //获取选中项
        if(!nodeSelected){
            layerror("请选择组织！");
            return ;
        }
        var obj = table.checkStatus('companyTable');
        if(!obj || obj.data.length<1){
            layself("请至少选择一项信息！");
            return false;
        }
        var ids = new Array();
        for(var i=0;i<obj.data.length;i++){
            ids.push(obj.data[i].id);
        }
        var nodes = zTreeObj.getSelectedNodes()[0];
        layui.use(['layer'],function(){
            var layer = layui.layer;
            layer.confirm('确定删除？', {
                btn: ['确定', '取消'] //可以无限个按钮
            }, function(){
                var delurl = "company/deleteAll";
                var data = {"idStr":ids.join(",")};//删除
                publicAjax (null,delurl,data,null,null,function (r) {
                    if(r.code==2000){
                        laysuccess("删除成功");
                        initTree("#treeStructure");
                        initTable(r.data);
                    }else{
                        layerror("删除失败")
                    }
                })
            }, function(){
                layer.closeAll();

            });
        })
    }



    function initForm(node){
        obj_datas = node;
        $(".org-attr td :input").attr("disabled", "disabled");
        $("#name").val(node.name);
        $("#shortName").val(node.shortName);
        $("#sort").val(node.sort);
        $("#orgCode").val(node.orgCode);
        $("#domainName").val(node.domainName);
        $("#phone").val(node.phone);
        $("#fax").val(node.fax);
        $("#postalCode").val(node.postalCode);
        $("#gps").val(node.gps);
        $("#address").val(node.address);
        $("#webSite").val(node.webSite);
        $("#type").val(node.type);
        $("#state").val(node.state);
        $("#hierarchy").val(node.hierarchy);
        form.render();

    }

    function getProlist(node){
        //获取选中的node
        var pid = node.id;
        publicAjax(null,"company/getByPid",{"id":pid},false,null,function(data){
            if(data.code==2000){
                initTable(data.data);
            }
        })
    }

    function initTable(data){
        var cols = [
            [  {type:'checkbox',
                width: '8px',},{
                title: '序号',
                type: 'numbers',
                align: 'center'
            }, {
                field: 'name',
                title: '名称',
                sort: true,
                align: 'center',
                width: '30%'
            }, {
                field: 'shortName',
                title: '简称',
                sort: true,
                align: 'center',
                width: '20%'
            }, {
                field: 'type',
                title: '组织类型',
                sort: true,
                align: 'center',
                width: '15%',
                templet: function(d) {
                    var value = "";
                    switch(d.type){
                        case 1:
                            value = "公司";
                            break;
                        case 2:
                            value = "部门";
                            break;
                        case 3:
                            value = "虚拟组织";
                            break;
                        case 4:
                            value = "项目部";
                            break;
                    }
                    return value ;
                }
            },  {
                field: 'hierarchy',
                title: '组织级别',
                sort: true,
                align: 'center',
                width: '15%',
                templet: function(d) {
                    var value = orgLevelMap.get(d.hierarchy+"");
                    return value ;
                }
            }, {
                field: 'sort',
                title: '排序',
                sort: true,
                width: '10%',
                align: 'center'
            }]
        ]
        layui.use('table', function(){
            table = layui.table;
            table.render({
                elem: '#companyTable',
                size: 'sm',
                limit:10000,
                headers: {"Authorization":getData("Authorization")},
                height: 'full-500',
                data: data,
                cols: cols,
                page: false
            });
        })
    }

    //点击确定后修改页面
    function initSave(val) {
            if(!$("#name").val().replace(/^ +| +$/g,'')) {
                layer.msg('请输入全称！', {
                    time: 1000
                });
                return;
            }
            var url = 'company/insertOrUpdate';
            var json ={
                id:obj_datas.id,
                parentId:obj_datas.parentId,
                name:$("#name").val(),
                shortName:$("#shortName").val(),
                sort:$("#sort").val(),
                orgCode:$("#orgCode").val(),
                domainName:$("#domainName").val(),
                phone:$("#phone").val(),
                fax:$("#fax").val(),
                webSite:$("#webSite").val(),
                address:$('#address').val(),
                postalCode:$("#postalCode").val(),
                state:$("#state").val(),
                type:$("#type").val(),
                hierarchy:$("#hierarchy").val(),
                gps:$("#gps").val()
            }
            publicAjax(null,url,json,null,null,function (data){
                if(data.code==2000){
                    // initTree("#treeStructure");
                    if(parentNode==null){
                        initTree("#treeStructure");
                    }else{
                        zTreeObj.reAsyncChildNodesPromise(parentNode,'refresh');
                    }
                    initForm(json);
                    //$("#edit,#state,#hierarchy,#type").css('display','inline-block');
                    $("#save,#back,#project_gps_btn").css('display','none');
                    form.render();
                    $(val).attr("onclick","initEdit(this)");
                    $(val).html("<i class='layui-icon'>&#xe608;</i>编辑");
                    $("#canceEndit").remove();

                }else{
                    layer.alert(data.msg);
                }
            })
    }

    function submitcreate(url) {
        if(!$("#addcom input[name='name']").val().replace(/^ +| +$/g,'')) {
            layer.msg('请输入名称！', {
                time: 1000
            });
            return;
        }
        /*var fax=jQuery.trim(jQuery("#addcom input[name='fax']").val());
        if((''!=fax) && !(mCheck(fax,'fax'))){
            layer.msg('传真格式不正确',{time: 1000});
            return ;
        }
        var telephone=jQuery.trim(jQuery("#addcom input[name='phone']").val());
        if((''!=telephone) && !(mCheck(telephone,'compmobile'))){
            layer.msg('公司电话格式不正确',{time: 1000});
            return ;
        }
        // ^[0-9]\\d{5}$
        var postalcode=jQuery.trim(jQuery("#addcom input[name='postalCode']").val());
        if((''!=postalcode)&&  !(mCheck(postalcode,'postalcode'))){
            layer.msg('邮编格式不正确',{time: 1000});
            return ;
        }

        var website=jQuery.trim(jQuery("#addcom input[name='webSite']").val());
        if((''!=website)&&(!(/http(s)?:\/\/([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?/.test(website)))){
            layer.msg('网站格式不正确',{time: 1000});
            return ;
        }*/
        var data = $('#formTest').serializeJson();
        console.log(data);
        var newNode = data;
        newNode.parent = true;
        var urls = url;
        publicAjax(null,urls,data,null,null,function (data){
            if(data.code==2000){
                form.val("formTest1", {
                    name: '',
                    shortName: '',
                    type:'',
                    hierarchy:'',
                    state:'',
                    sort:'',
                    orgCode:'',
                    domainName:'',
                    phone: '',
                    state: '',
                    webSite: '',
                    postalCode: '',
                    address: '',
                    fax: '',
                    gps:''
                });
                layer.close(index_i1);
                //initTree("#treeStructure");
                zTreeObj.reAsyncChildNodes(nodeSelected, "refresh");
                if(index_i1) {

                }else{
                    $("#formTest1 select[name='state']").val(1)
                    form.render("select");
                }
            }else{
                layer.alert(data.msg);
            }
        })
    }
    var overlays_one = [];
    var mk ;
    function getGps() {
        var e = document.all ? window.event : arguments[0] ? arguments[0] : event;
        e.stopPropagation();
        e.preventDefault();
        var index = layer.open({
            type: 1,
            title: '选择GPS',
            maxmin: true,
            shadeClose: false, //点击遮罩关闭层
            area: ['750px', '480px'],
            content: $("#gpsmap"),
            btn: ['确定'],
            success: function () {
                $('.layui-layer-btn .layui-layer-btn0').css({
                    'border-color': '#1E9FFF ',
                    'background-color': '#1E9FFF'
                })
                // 百度地图API功能
                map = new BMap.Map('map');
                if ($("input[name='gps']").val()) {
                    var arr = $("input[name='gps']").val().split(',')
                    var poi = new BMap.Point(arr[0], arr[1]);
                } else {
                    var poi = new BMap.Point(117.227737, 31.828551);
                }
                map.centerAndZoom(poi, 10);
                mk = new BMap.Marker(poi);//创建标注图标
                overlays_one.push(mk);
                map.addOverlay(mk);//将标注添加到地图中
                map.enableScrollWheelZoom();
                var overlaycomplete = function (e) {
                    overlays_one = [];
                    overlays_one.push(e.overlay);
                    overlays.push(e.overlay);
                };
                var styleOptions = {
                    strokeColor: "red", //边线颜色。
                    fillColor: "red", //填充颜色。当参数为空时，圆形将没有填充效果。
                    strokeWeight: 3, //边线的宽度，以像素为单位。
                    strokeOpacity: 0.8, //边线透明度，取值范围0 - 1。
                    fillOpacity: 0.6, //填充的透明度，取值范围0 - 1。
                    strokeStyle: 'solid' //边线的样式，solid或dashed。
                }
                //实例化鼠标绘制工具
                var drawingManager = new BMapLib.DrawingManager(map, {
                    isOpen: false, //是否开启绘制模式
                    enableDrawingTool: true, //是否显示工具栏
                    drawingToolOptions: {
                        anchor: BMAP_ANCHOR_TOP_RIGHT, //位置
                        offset: new BMap.Size(5, 5), //偏离值
                        scale: 0.8, //工具栏缩放比例
                        drawingModes: [BMAP_DRAWING_MARKER]
                    },
                    circleOptions: styleOptions, //圆的样式
                    polylineOptions: styleOptions, //线的样式
                    polygonOptions: styleOptions, //多边形的样式
                    rectangleOptions: styleOptions //矩形的样式
                });
                var timer, count = 0;
                map.addEventListener("click", function (e) {
                    clearAll();
                    count++;
                    timer = window.setTimeout(function () {
                        if (count == 1) {
                            console.log(e.point.lng + '|' + e.point.lat);
                        }
                        window.clearTimeout(timer);
                        count = 0;
                    }, 300)
                });
                drawingManager.addEventListener('overlaycomplete', overlaycomplete);
            },
            yes: function (index, layero) {
                $('.layui-layer-btn .layui-layer-btn0').css({
                    'border-color': '#FFC107',
                    'background-color': '#FFC107'
                })
                $("input[name='gps']").val(overlays_one[0].point.lng + ',' + overlays_one[0].point.lat);
                layer.close(index);
            },
            cancel: function (index, layero) {
                $('.layui-layer-btn .layui-layer-btn0').css({
                    'border-color': '#FFC107',
                    'background-color': '#FFC107'
                })
            }
        });
    }

    function clearAll() {
        if(mk) map.removeOverlay(mk);
        if(overlays.length > 1) {
            for(var i = 0; i < overlays.length; i++) {
                if(i != overlays.length - 1) {
                    map.removeOverlay(overlays[i]);
                }
            }
        }
    }


</script>
</html>